//
//  HMLoginViewController.m
//  localLife
//
//  Created by Limonwei on 15/11/23.
//  Copyright © 2015年 heima. All rights reserved.
//

#import "HMLoginViewController.h"
#import "UMSocial.h"
#import "MBProgressHUD.h"

@interface HMLoginViewController ()
@property (weak, nonatomic) IBOutlet UIView *userView;
@property (weak, nonatomic) IBOutlet UIView *passwordView;
@property (weak, nonatomic) IBOutlet UITextField *userNameTextFiled;
@property (weak, nonatomic) IBOutlet UITextField *passWordTextFiled;
@property (weak, nonatomic) IBOutlet UIImageView *userImage;
@property (weak, nonatomic) IBOutlet UIImageView *passwordImage;
- (IBAction)LoginBtn:(id)sender;
@property (weak, nonatomic) IBOutlet UIButton *LoginBtn;
- (IBAction)remberBtn:(id)sender;
@property (weak, nonatomic) IBOutlet UIImageView *remberBtnImage;

@end

@implementation HMLoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.titltLabel.text = @"登陆";
    
    self.rightButton.hidden = YES;
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    _userView.backgroundColor = Login_Light_Color;
    _userImage.backgroundColor = Login_Deep_Color;
    _userView.layer.cornerRadius = 5;
    _userView.clipsToBounds = YES;
    
    _passwordImage.backgroundColor = Login_Deep_Color;
    _passwordView.backgroundColor = Login_Light_Color;
    
    
    _LoginBtn.backgroundColor = Login_Light_Color;
    _LoginBtn.enabled = NO;
    
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(loginBtnClick) name:UITextFieldTextDidChangeNotification object:self.userNameTextFiled];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(loginBtnClick) name:UITextFieldTextDidChangeNotification object:self.passWordTextFiled];
    
    
    
    
}

-(void)dealloc{
    
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}

-(void)loginBtnClick{
    
    self.LoginBtn.enabled = (self.userNameTextFiled.text.length>0 && self.passWordTextFiled.text.length>0);
    
}

-(void)back{
    
    [self.navigationController popViewControllerAnimated:YES];
    
    AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
    
    [app.tabbar showOrHiddenTabbarView:NO];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

// 点击屏幕回退键盘
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    
    [_userNameTextFiled resignFirstResponder];
    
    [_passWordTextFiled resignFirstResponder];
    
}



- (IBAction)LoginBtn:(id)sender {
    
    NSString *userName = self.userNameTextFiled.text;
    NSString *password = self.passWordTextFiled.text;
    
    if ([userName isEqualToString:@"18310820688"] && [password isEqualToString:@"123456"]) {
        //登录成功
        [self.view endEditing:YES];
        
        [self SHOWloadView];
        
        //跳转到个人中心界面
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            //
            [self dismissLoadView];
            
            //[self performSegueWithIdentifier:@"Login" sender:nil];
        });
    }else{
        
        
    }
    
    
}
- (IBAction)remberBtn:(id)sender {
    
}



#pragma mark --第三方登录

- (IBAction)shareWB:(id)sender {
    
    [self UMshareWithName:UMShareToSina];
}
- (IBAction)shareDB:(id)sender {
    
    [self UMshareWithName:UMShareToDouban];
}
- (IBAction)shareQQ:(id)sender {
    
    [self UMshareWithName:UMShareToQzone];
}
- (IBAction)shareWX:(id)sender {
    
    [self UMshareWithName:UMShareToTencent];
}


-(void)UMshareWithName:(NSString *)name{
    
    [UMSocialData setAppKey:@"507fcab25270157b37000010"];
    
    UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:name];
    
    snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
        
        //          获取微博用户名、uid、token等
        
        if (response.responseCode == UMSResponseCodeSuccess) {
            
            UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:name];
            
            NSLog(@"username is %@, uid is %@, token is %@ url is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL);
            
            // 获取到用户信息之后, 我们自己可以调用注册接口.
            
        }});

    
    
    
}
@end

















